{% extends 'base.html' %}
{% load static %}

{% block title %}兑换记录 - Meet活动聚{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="row">
        <div class="col-12">
            <!-- 添加导航面包屑和返回按钮 -->
            <nav aria-label="breadcrumb" class="mb-3">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{% url 'home' %}">首页</a></li>
                    <li class="breadcrumb-item"><a href="{% url 'points:points_home' %}">我的积分</a></li>
                    <li class="breadcrumb-item active">兑换记录</li>
                </ol>
            </nav>

            <!-- 页面标题和返回按钮 -->
            <div class="d-flex justify-content-between align-items-center mb-4">
                <div>
                    <h3>我的兑换记录</h3>
                    <p class="text-muted mb-0">查看您的奖品兑换历史</p>
                </div>
                <a href="{% url 'points:rewards_shop' %}" class="btn btn-primary">
                    <i class="bi bi-arrow-left me-2"></i>返回商城
                </a>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-12">
            {% if exchanges %}
            <div class="card">
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>奖品名称</th>
                                    <th>消耗积分</th>
                                    <th>兑换时间</th>
                                    <th>状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for exchange in exchanges %}
                                <tr>
                                    <td>
                                        <div class="d-flex align-items-center">
                                            {% if exchange.reward.image %}
                                            <img src="{{ exchange.reward.image.url }}" alt="{{ exchange.reward.name }}"
                                                 class="rounded me-3" style="width: 50px; height: 50px; object-fit: cover;">
                                            {% else %}
                                            <div class="rounded bg-light d-flex align-items-center justify-content-center me-3"
                                                 style="width: 50px; height: 50px;">
                                                <i class="bi bi-gift text-muted"></i>
                                            </div>
                                            {% endif %}
                                            <div>
                                                <strong>{{ exchange.reward.name }}</strong>
                                                <br>
                                                <small class="text-muted">{{ exchange.reward.get_type_display }}</small>
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <span class="text-danger">-{{ exchange.points_used }}</span>
                                    </td>
                                    <td>{{ exchange.created_at|date:"Y-m-d H:i" }}</td>
                                    <td>
                                        {% if exchange.status == 'pending' %}
                                            <span class="badge bg-warning">待处理</span>
                                        {% elif exchange.status == 'completed' %}
                                            <span class="badge bg-success">已完成</span>
                                        {% else %}
                                            <span class="badge bg-danger">已取消</span>
                                        {% endif %}
                                    </td>
                                    <td>
                                        {% if exchange.status == 'pending' %}
                                            <button class="btn btn-sm btn-outline-secondary" disabled>等待处理</button>
                                        {% elif exchange.status == 'completed' %}
                                            <span class="text-success">
                                                <i class="bi bi-check me-1"></i>已完成
                                                {% if exchange.completed_at %}
                                                <br><small>{{ exchange.completed_at|date:"m-d H:i" }}</small>
                                                {% endif %}
                                            </span>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <!-- 底部返回按钮 -->
            <div class="text-center mt-4">
                <a href="{% url 'points:rewards_shop' %}" class="btn btn-outline-primary">
                    <i class="bi bi-arrow-left me-2"></i>返回积分商城
                </a>
            </div>

            {% else %}
            <div class="text-center py-5">
                <i class="bi bi-clock-history text-muted display-1"></i>
                <h4 class="text-muted mt-3">暂无兑换记录</h4>
                <p class="text-muted">您还没有兑换过任何奖品</p>
                <div class="mt-4">
                    <a href="{% url 'points:rewards_shop' %}" class="btn btn-primary me-3">
                        <i class="bi bi-cart-check me-2"></i>去积分商城
                    </a>
                    <a href="{% url 'points:points_home' %}" class="btn btn-outline-primary">
                        <i class="bi bi-wallet2 me-2"></i>返回积分首页
                    </a>
                </div>
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %}